package com.monicaca.controller;



import com.monicaca.bean.User;
import com.monicaca.bean.WLK;
import com.monicaca.service.WLKService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;


import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/WLK")
public class WLKController {
    @Autowired
    WLKService wlkService;
    @Autowired
    HttpServletRequest request;

   
    @GetMapping("/")
    public String indexView(
            Model model){
        model.addAttribute("WLK",wlkService.findAll());
        return "WLK";
    }
    @GetMapping("/add")
    public String addView(
            Model model){
        return "WLKadd";
    }
    
    @PostMapping("/save")
    public String updateView(
            Model model, WLK wlk){	
    	int id=wlk.getId();
  
        WLK wlk3=wlkService.findByRKDId(id);
        if(wlk3!=null){
        	model.addAttribute("msg","该物料编码已经存在，请重新设定物料编码！");
        	model.addAttribute("WLK",wlkService.findAll());
        	return "WLK";
        }
        wlkService.createWLK(wlk);
        model.addAttribute("msg","新增成功");
        model.addAttribute("WLK",wlkService.findAll());
      
        return "WLK";
    }
    
 
    @GetMapping("/delete/{id}")
    public String deteleView(
            Model model, @PathVariable int id){

        wlkService.deleteWLK(id);
        model.addAttribute("msg","删除成功");
        model.addAttribute("WLK",wlkService.findAll());
        return "WLK";
    }


}
